<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>生产计划编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/logic/proplan";
var grid;
	$(function(){
		$("#inputForm").validate({			   
			onsubmit: true,
		 	/*执行ajaxsubmit  */ 
	    	submitHandler: function(editform) {
	        	//alert(jsonInfo); 
	        	try{			    		
	            	url =  basic_Url+"/save.do";
	            	var api = frameElement.api;
	        		var W = api.opener;
	        
	            	getReturnMessage(url,"inputForm",W.searchAP);
	        	}catch(e){alert(e);}
	    	}
	});
	$("#save").hide();
	$("#tijiao").hide();
	if('${proplan.zd008Billstatus}'=="PROPLAN_SAVE"||'${proplan.zd008Billstatus}'==""||'${proplan.zd008Billstatus}'==null){
		$("#save").show();
		$("#tijiao").show();
	}
	if('${proplan.zd008Billstatus}'=='PROPLAN_AUDIT'){
		$("#check").show();
	}else{
		$("#check").hide();
	}
	
	grid = $("#dataGrid").ligerGrid({
	    columns: [{ display: 'ID', name: 'id', width: 1 , hide:true},
	              { display: '产品id', name: 'zd006MaterialsId', width: 1 , hide:true},
	              { display: '<font color="gray">产品编码</font>', name: 'zd007MaterialsCode',  width: 100},
				  { display: '<font color="gray">产品名称</font>', name: 'zd008MaterialsName', width: 100 },
				  { display: '<font color="gray">产品型号</font>', name: 'zd010MaterialsModel', width: 100},
				  { display: '<font color="gray">产品尺寸</font>', name: 'zd038MaterialsSize', width: 160},
				  { display: '<font color="gray">产品颜色</font>', name: 'zd041MaterialsColor', width: 60},
				  { display: '<font color="gray">产品材质</font>', name: 'zd042MaterialsQuality', width: 60},
				  { display: '<font color="gray">计量单位</font>', name: 'zd012MaterialsUnit', width: 60},
				  { display: '<font color="gray">数量</font>', name: 'zd013Quantity', width: 80},
	              { display: '<font color="gray">产品描述</font>', name: 'zd036MaterialsDescription', width: 150}
	              ],
	              enabledEdit: false,
	              usePager: true,pageSize:1000,pageSizeOptions:[1000],
	              parms:[{ name : 'id' , value : '${proplan.id}'}],
	              url : basic_Url+"/griditems.do",
	              width: "100%", height:'90%', checkbox: true
	 });
	
}); 

//选择物料
function ItemWindow(){
	getDG().dialog({
		title : '选择产品',
		width : 650,
		height : 350,
		content : 'url:' + sys_context+ '/public/windowalert/cpitem.do',    //查询所有物料，不区分成品和原材料  
		lock : true,
		max : true,
		min : true,
		ok : function() {
			var getSelectedHub = this.content.getSelected();
			var manager = $("#dataGrid").ligerGetGridManager();
			if (getSelectedHub != null) {
				$(getSelectedHub).each(function() {
					manager.addRow2({
						zd008MaterialsName : this.zd002Name,
						zd017Price : this.zd009Price.toFixed(4),
						zd010MaterialsModel : this.zd004Model,
						zd012MaterialsUnit : this.basicStapleUnitDO.zd002Name,
						zd006MaterialsId: this.id,//物料ID
						zd041MaterialsColor : this.zd033Color,
						zd036MaterialsDescription:this.zd006Description,
						zd042MaterialsQuality:this.zd034Quality,
						zd038MaterialsSize:this.zd026Size,
						zd007MaterialsCode:this.zd001Code
					});
				});
			}
			this.content.Close();
			return false;
		},
		cancelVal : '关闭',
		cancel : true
	}).zindex();
}
function deleteRow(){
	grid.deleteSelectedRow();
}
function submitForm(param){
	$("#paramflag").val(param);
	var data = grid.getData();
	if (data.length == 0) {
		$.dialog.alert("您没有选择具体生产的产品，无法操作！");
		return false;
	}
	var ba = true;
	jQuery.ajaxSettings.async = false;
	if (ba) {
		$("#itemdata").val(JSON.stringify(data));
		$("#submitFlag").val(param);
		$("#inputForm").submit();
	}
 }		

//客户列表
function CompanyWindow() {
	getDG().dialog(
			{
				title : '选择客户',
				width : 650,
				height : 350,
				content : 'url:' + sys_context
						+ '/public/windowalert/company.do?zdType='+'cust',    
				lock : true,
				max : true,
				min : true,
				ok : function() {
					var rows = this.content.getSelected();
					if (rows != null) {
						$(rows).each(function() {
							$("#zd004CustomerId").val(this.id);
							$("#zd004CustomerCode").val(this.zd001Code);
							$("#zd004CustomerName").val(this.zd003ZhName);
						});
					}
					this.content.Close();
					return false;
				},
				cancelVal : '关闭',
				cancel : true
			}).zindex();
}

//PI编号列表
function PICodeWindow() {
	getDG().dialog({
			title : '选择PI编号',
			width : 650,
			height : 350,
			content : 'url:' + sys_context+ '/public/windowalert/picode.do',    
			lock : true,
			max : true,
			min : true,
			ok : function() {
				var rows = this.content.getSelected();
				var id="";
				if (rows != null) {
					$(rows).each(function() {
						id=this.id;
						$("#zd003PiCode").val(this.zd002PiCode);
						$("#zd007SalesMan").val(this.zd022SalesMan);
						$("#zd002OriCode").val(this.zd001FormCode);
						$("#zd002OriId").val(this.id);
						
						$("#zd004CustomerId").val(this.zd004CustomerId);
						$("#zd004CustomerCode").val(this.zd005CustomerCode);
						$("#zd004CustomerName").val(this.zd006CustomerName);
						
						var zdType = this.zd028SaleType;
						$("#zd002OriType").val(this.zd028SaleType);
						if('BT'==zdType){
							$("#zd002Type").val("套床");
						}
						if('MT'==zdType){
							$("#zd002Type").val("床垫");
						}
						$("#zd005OrderDate").val(formatDate(new Date(this.bizCreatorDate),"yyyy-MM-dd"));
						$("#zd006DeliveryDate").val(formatDate(new Date(this.zd017DeliveryDate),"yyyy-MM-dd"));
						$("#zd009Remark").val(this.zd023Remark);
						$("#zd010CurrencyCode").val(this.zd014CurrencyCode);
						$("#zd010CurrencyName").val(this.zd014CurrencyName);
						$("#zd011ExchangeRate").val(this.zd015ExchangeRate);
						
						
					});
				}
				if(id!=null&&id!=""){
					multipleSearch("#dataGrid",true,"","${ctx}/logic/sales/griditems.do?id="+id);
				}
				this.content.Close();
				return false;
			},
			cancelVal : '关闭',
			cancel : true
		}).zindex();
}

function checkback(){
	$.ajax({
		url:basic_Url+"checkBack.do",
		global: false,
	 	type: 'POST',
	 	dataType:'json',
		data : ({
	 		id:"${proplan.zd001FormCode}"
	 	}),success: function(data){
	 		if(data.msg=='yes'){
	 			back("${proplan.zd001FormCode}");
	 		}else{
	 			$.dialog.alert("您的单据，以派工不能再进行驳回操作");
	 		}
	 	}
	});
}

function back( zd001FormCode ){
	
}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${proplan.id}"/>
<input type="hidden" id="bizVersion" name="bizVersion" value="${proplan.bizVersion}"/>
<input type="hidden" id="zd010CurrencyCode" name="zd010CurrencyCode" value="${proplan.zd010CurrencyCode}"/>
<input type="hidden" id="zd010CurrencyName" name="zd010CurrencyName" value="${proplan.zd010CurrencyName}"/>
<input type="hidden" id="zd011ExchangeRate" name="zd011ExchangeRate" value="${proplan.zd011ExchangeRate}"/>
<input type="hidden" id="itemdata" name="itemdata"/>
<input type="hidden" id="paramflag" name="paramflag"/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         			<c:if test="${not empty proplan.zd001FormCode}">
         			<tr>
                    <td>生产计划单号:</td>
   		                 <td colspan="3">
   		                	<input type="text" id="zd001FormCode" name="zd001FormCode" disabled="disabled" style="width: 40%;"  value="${proplan.zd001FormCode}" />
   		                 </td>
   		           </tr>
   		           </c:if>
   		           <tr>
                      <td >PI编号:</td>
   		                 <td>
   		                	<input type="text" id="zd003PiCode" name="zd003PiCode" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd003PiCode}" />
   		                	<input type="button" value="..." onclick="PICodeWindow();" />
   		                 </td>
   		                 <td >业务员:</td>
   		                 <td colspan="3">
   		                	<input type="text" id="zd007SalesMan" name="zd007SalesMan" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd007SalesMan}" />
   		                 </td>
   		           </tr>
                   <tr>
   		             <td >客户编码:</td>
   		                 <td>
   		                 <input type="hidden" id="zd004CustomerId" name="zd004CustomerId" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd004CustomerId}" />
   		                 <input type="text" id="zd004CustomerCode" name="zd004CustomerCode" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd004CustomerCode}" />
   		                 <!-- <input type="button" value="..." onclick="CompanyWindow();" /> -->
   		                 </td>  
   		              <td >客户名称:</td>
   		                 <td>
   		                <input type="text" id="zd004CustomerName" name="zd004CustomerName" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd004CustomerName}" />
   		                 </td>     
   		           </tr>
   		           <tr>
   		           		<td>销售订单号:</td>
   		                <td>
   		                	<input type="hidden" id="zd002OriId" name="zd002OriId" value="${proplan.zd002OriId }"/>
   		                	<input type="text" id="zd002OriCode" name="zd002OriCode" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd002OriCode}" />
   		                </td>
   		                <td>产品类型:</td>
   		                <td>
   		                	<input type="hidden" id="zd002OriType" name="zd002OriType" class="required" readonly="readonly" style="width: 40%;" value="${proplan.zd002OriType}" />
   		                	<input type="text" id="zd002Type" class="required" readonly="readonly" style="width: 40%;" value="" />
   		                	<script type="text/javascript">
   		                		var zd002OriType = '${proplan.zd002OriType}';
   		                		if('BT'==zd002OriType){
   		                			$("#zd002Type").val("套床");
   		                		}
   		                		if('MT'==zd002OriType){
   		                			$("#zd002Type").val("床垫");
   		                		}
   		                	</script>
   		                </td>
   		           </tr>
   		           <tr>
                    	<td >订单日期:</td>
   		                 <td>
   		                	<input type="text" id="zd005OrderDate" name="zd005OrderDate" readonly="readonly" style="width: 40%;" class="required" class="Wdate" value="<fmt:formatDate value="${proplan.zd005OrderDate}" pattern="yyyy-MM-dd" type="both" />"/>
   		                 </td>
   		                 <td >交货日期:</td>
   		                 <td>
   		                	<input type="text" id="zd006DeliveryDate" name="zd006DeliveryDate" readonly="readonly" style="width: 40%;" class="Wdate" value="<fmt:formatDate value="${proplan.zd006DeliveryDate}" pattern="yyyy-MM-dd" type="both" />"/>
   		                 </td>
   		           </tr>
   		           <tr>
   		           	<td >备注:</td>
   		           	<td>
   		           		<input id="zd009Remark" name="zd009Remark" style="width: 40%;" value="${proplan.zd009Remark}" />
   		           	</td>
   		           	<td >附件:</td>
   		           	<td>
   		           		<input type="button" value="查看附件..." onclick="uploadFileWindow('zd002OriId','plan');" />
   		           	</td>
   		           </tr>
   		           <tr>
						<td colspan="4" style="margin-bottom: 10px;"><div
								id="dataGrid"></div></td>
					</tr>
                </table>               
         </div>
         <div class="formBar">
	        <ul>
	        	 <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="checkback" onclick="checkback();">驳回</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm('PROPLAN_SAVE')">保存</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="tijiao" onclick="submitForm('PROPLAN_AUDIT')">提交</button></div></div></li>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
